#ifndef HTTPMANAGER_H
#define HTTPMANAGER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QUrl>
#include <QJsonObject>
#include <QJsonDocument>
#include <QNetworkReply>



#include "global.h"
#include "Singleton.h"

//CRTP模式
class HttpManager : public QObject,
        public Singleton<HttpManager>,
        public std::enable_shared_from_this<HttpManager>
{
    Q_OBJECT
public:
    /**
     * @brief PostHttpReq 发送http请求
     * @param url 请求url
     * @param json 请求的数据
     * @param req_id 请求的id
     * @param mod 发送请求的模块
     */
    void PostHttpReq(QUrl url, QJsonObject json, ReqId req_id, Modules mod);
    ~HttpManager();
private:

    //为了让基类Singleton初始化，需要设置为友元
    friend class Singleton<HttpManager>;
    HttpManager();
    QNetworkAccessManager _manager;
signals:
    /**
     * @brief sig_http_finish http 请求完成
     */
    void sig_http_finish(ReqId id, QString res, ErrorCodes err, Modules mod);

    /**
     * @brief sig_http_finish http 注册模块完成
     */
    void sig_reg_mod_finish(ReqId id, QString res, ErrorCodes err);
private slots:
    void slot_http_finish(ReqId id, QString res, ErrorCodes err, Modules mod);
};

#endif // HTTPMANAGER_H
